﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LitJson;

public class CardItemList : MonoBehaviour
{
    public static List<CardItem> cardItemList = new List<CardItem>();

    void Start()
    {
        ReadCardItemJson();
    }

    private void ReadCardItemJson()
    {
        string json = "CardItemJson";

        TextAsset jsonText = Resources.Load<TextAsset>(json);

        JsonData jsonMapper = JsonMapper.ToObject(jsonText.text);

        for (int i = 0; i < jsonMapper.Count; i++)
        {
            int id = (int)jsonMapper[i]["id"];
            string mainSprite = (string)jsonMapper[i]["mainSprite"];
            string boxSprite = (string)jsonMapper[i]["boxSprite"];
            string des = (string)jsonMapper[i]["des"];

            CardItem cardItem = new CardItem(id, mainSprite, boxSprite, des);

            cardItemList.Add(cardItem);
        }
    }

    public static CardItem GetCardItemById(int id)
    {
        return cardItemList[id];
    }    
}
